package com.woniuxy.servicelayer.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.dal.entity.Test;
import com.woniuxy.dal.mapper.TestMapper;
import com.woniuxy.servicelayer.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
* @author rjq51
* @description 针对表【test(实验表)】的数据库操作Service实现
* @createDate 2023-03-27 17:02:43
*/
@Service
public class TestServiceImpl extends ServiceImpl<TestMapper, Test>
    implements TestService {
    @Autowired
    TestMapper testMapper;

    /**
     * 查询所有的实验列表
     */
    @Override
    public List<Test> selectTestList() {
        return testMapper.selectList(null);
    }

    /**
     * 按条件排序实验 模糊搜索
     */
    @Override
    public List<Test> testConditionalQuery(Integer instruction, String keyword) {
        QueryWrapper<Test> testQueryWrapper = new QueryWrapper<>();
        if(instruction != null){
            switch (instruction){
                case 1:testQueryWrapper.orderByDesc("createTime");
                case 2:testQueryWrapper.orderByDesc("visitorsCount");
            }
        }
        if(!StringUtils.isEmpty(keyword)){
            testQueryWrapper.like("testName",keyword);
        }
        return testMapper.selectList(testQueryWrapper);
    }
}




